export function generateFuzzyQuery (value) {
  return new RegExp(`(.*)(${value.split('').join(')(.*)(')})(.*)`, 'i')
}

export function fuzzyQuery (dataSources, keyword) {
  if (dataSources && dataSources.length > 0) {
    const reg = generateFuzzyQuery(keyword)
    const arr = dataSources.filter(item => {
      return reg.test(item)
    })
    return arr
  }
  return []
}

function getStanderArr (dataSources, keyword) {
  if (dataSources && dataSources.length > 0) {
    const reg = generateFuzzyQuery(keyword)
    const arr = []
    dataSources.forEach(item => {
      const newItem = {}
      if (reg.test(item)) {
        newItem.name = item
        arr.push(newItem)
      }
    })
    return arr
  }
  return []
}

export function getSchoolQuery (dataSources, keyword) {
  return getStanderArr(dataSources, keyword)
}

export function getProfessionQuery (dataSources, keyword) {
  return getStanderArr(dataSources, keyword)
}
